package com.breakfast.fun.ui.user.help;

import com.breakfast.fun.data.entity.user.help.Help;
import com.breakfast.fun.util.Api;
import com.breakfast.fun.util.T;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Administrator on 2016/9/9.
 */
public class HelpCenterPresenter extends HelpCenterContract.Presenter {
    @Override
    public void getHelp() {
        Map<String, String> map = Api.getInstance().getBaseParams();

        showLoadingDialog(true);

        rxManager.add(model.getHelpModel(map)
                .subscribeOn(Schedulers.computation())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new Subscriber<Help>() {
                    @Override
                    public void onCompleted() {
                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        T.show("获取数据失败");
                    }

                    @Override
                    public void onNext(Help help) {
                        if (help.isSuccess()) {
                            view.showHelp(help);
                        } else {
                            T.show(help.getMsg());
                        }
                        hideLoadingDialog();
                    }

                }));
    }

    @Override
    public void onStart() {
        getHelp();
    }
}
